package com.zlsy.secondtime.threadcoreknowledge.stopthreads;


/**
 * @author zhouliang
 * @date 2020/5/15 9:55
 * <p>
 */
public class CannotInterrupt implements Runnable {

    @Override
    public void run() {
        int num = 0;
        while (num < 3000 && !Thread.currentThread().isInterrupted()) {
            if (num % 100 == 0) {
                System.out.println("当前num: " + num);
            }
            num++;
            try {
                //Thread.sleep当它一旦响应中断，编
                Thread.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) throws InterruptedException {
        CannotInterrupt r = new CannotInterrupt();
        Thread thread = new Thread(r);
        thread.start();
        Thread.sleep(1000);
        thread.interrupt();
    }
}
